
import axios from 'axios'
import {Ajax} from 'config/config'
import {encrypt, Alert, signs, Error} from './deal'

export const Logins=(userName,Password)=>{
				
  if(userName && Password !=''){
  	axios.post(`${Ajax}/session`,{
			username:userName,
			password:encrypt(Password),
		}).
		then((response)=>{
			
			Alert(response.data,'LOGIN')
			
		})
  }else{
  	Alert(Error('请输入账号或密码!'))
  }
}

export const Exit=(Token)=>{
	
	axios({
		method: 'delete',
		url: `${Ajax}/system/4/session`,
		data:{
			access_token:Token,
			sign:signs(),
		}}).then((response)=>{
			
			Alert(response.data,'EXIT');
			
		})
}

export const userIfo=(Token)=>{
	
	return axios.get(`${Ajax}/system/4/session?
									access_token=${Token}&sigin=${signs()}`
				).then((response)=>{
					
						return response.data.data.fullName;
						
					}).catch((error)=>{
						
						Alert(Error(error.response.data.error_description));
						
						setTimeout(()=>location.href = "./",3500);
						
					})
}
